﻿using System;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.IO;

namespace Cofe.Core
{


    /// <summary>
    /// Logger implementation. 
    /// </summary>
    [Export(typeof(ICofeService))]
    [ServicePriority(ServicePriorityAttribute.DefaultPriority_NONE)]
    public class DummyLogger : ILogger
    {

        public void Log(string msg)
        {            
        }

        public void Log(Exception exc)
        {
         
        }

        public void Log(string format, params object[] arg)
        {
         
        }

        public void Log(string pMessage, Category pCategory, Priority pPriority)
        {
         
        }
    }

    /// <summary>
    /// Logger implementation. 
    /// </summary>
    [Export(typeof(ICofeService))]
    [ServicePriority(ServicePriorityAttribute.DefaultPriority_COFE)]
    public class DebugLogger : ILogger
    {

        public void Log(string format, params object[] arg)
        {
            Log(String.Format(format, arg));
        }

        public void Log(string pMessage)
        {
            writeLogInfo(pMessage, Category.Info, Priority.None);
        }

        public void Log(Exception pException)
        {
            if (pException == null) return;
            writeLogInfo(pException.ToString(), Category.Exception, Priority.High);
        }

        public void Log(string pMessage, Category pCategory, Priority pPriority)
        {
            writeLogInfo(pMessage, pCategory, pPriority);
        }

        /// <summary>
        /// Writes the log message to the log file
        /// </summary>
        internal void writeLogInfo(string pMessage, Category pCategory,
          Priority pPriority)
        {
            if (string.IsNullOrEmpty(pMessage))
                pMessage = "Empty message received in LogWriterService";           

            string msg = String.Format("{0} - {1} - {2}",
              pMessage, pCategory, pPriority);
            Debug.WriteLine(msg);
        }
    }
}